
import string


class Order:
  def __init__(this,state,linkToDelete,(curr,price,lot,status)):
	this.state = state
	this.curr = curr
	this.price = float(price)
	this.lot = float(lot)
	this.status = status
	this.linkToDelete = linkToDelete
	this.number = linkToDelete.split('/')[-1].strip()

  def getDeleteCommand(): return this.linkToDelete

  def toString(this):
	return string.join((this.number,this.curr,"%.4f" % this.price,"%.3f" % this.lot,this.status,this.state),'\t')
  

class Tool:
  def __init__(this,v):
	this.name = v[0].upper()
	a = v[1].strip()[1:][:-1].upper()
	this.aliases  = map(string.strip,a.split(' '))
	this.ptsPrice = float(v[2])
	this.factor   = float(v[3])
	this.spread   = int(v[4])

  def hasAliase(this,aliase):
	z = aliase.upper()
	if z == this.name: return True
	for i in this.aliases:
	  if z == i: return True
	return False

  def getCanonicalName(this):
	return this.aliases[0]


class Position:
  def __init__(this,tool,v):
	this.tool = tool
	this.lot = float(v[1])
	this.mProfit = float(v[2])
	this.pProfit = int(v[3])
	this.openPrice = float(v[4])

  def setNumber(this,n):
	this.number = n

  def toString(this):
	return string.join((str(this.number),this.tool.getCanonicalName(),"%.3f" % this.lot,\
						  "%.2f (%d)" % (this.mProfit,this.pProfit),\
						  "%.4f" % this.openPrice),'\t')

  
